<?php

require_once('../include/GeneralTop.php');
require('../include/class/db.php');
require("../include/lib/fckeditor/fckeditor.php");

if (!$content_admin) {
	die('<div style="text-align:center">Permission denied...</div>');
}

$db = new db;

if ((isset($_POST["submit"]))) {
    $insertSQL = sprintf("UPDATE newsletter set title=%s, content=%s, cre_user=%d, upd_date=now()
							where id=%d",
                       GetSQLValueString($_POST['title'], "text"),
                       GetSQLValueString(stripslashes($_POST['FCKeditor1']), "text"),
                       GetSQLValueString($_SESSION['MM_Username_id'], "int"),
                       GetSQLValueString($_POST['id'], "int")
                       );

    $db->query($insertSQL);
    header("location:".$_SERVER['PHP_SELF']."?result=suc&id=".$_POST['id']);
}

$sql = sprintf("SELECT * FROM newsletter WHERE id = %d", GetSQLValueString($_GET['id'], "int"));
$res = $db->query($sql);
$row = $db->fetch($res);

include('AdminPanel.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>添加Newsletter</title>
<script src="../include/js/calendar.js" type="text/javascript"></script>
</head>

<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form1" id="form1">
  <table align="center" width="70%">
    <?php
    if($_GET['result'] && 'suc' == $_GET['result']) {
    ?>
    <tr valign="baseline">
      <td colspan="2" nowrap="nowrap" align="center"><font color="green">Edit newsletter successfully...</font></td>
    </tr>
    <?php
    }
    ?>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">title:</td>
      <td><input type="text" name="title" value="<?php echo $row['title']?>" size="50" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right" valign="top">content:</td>
      <td>
      <?php
	  $oFCKeditor = new FCKeditor('FCKeditor1') ;
	  $oFCKeditor->BasePath = FCKEDITOR_BASE_PATH;
	  $oFCKeditor->Height = 600;
	  $oFCKeditor->Value = $row['content'];
	  $oFCKeditor->Create();
	  ?>
      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">&nbsp;</td>
      <td>
      	<input type="submit" name="submit" id="submit" value="Edit record" />&nbsp;&nbsp;
      	<input type="button" id="button" onclick="window.location.href='SendNewsletter.php'" value="Back">
      </td>
    </tr>
  </table>
  <input type="hidden" name="id" value="<?php echo $_GET['id']?>">
</form>
<p>&nbsp;</p>
</body>
</html>